package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.HistoryDao;
import com.rmt.www.vo.Artifact;
import com.rmt.www.vo.History;

public class HistoryDaoImpl implements HistoryDao {

	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	@SuppressWarnings("unchecked")
	public List<History> getHistoriesByAid(int aid) {
		return (List<History>)(this.jdbcTemplate.query("select * from history where artifactid=?",
				new Object[]{aid}, 
				new int[]{java.sql.Types.INTEGER}, 
				new HistoryRowMapper()));
	}

	public void insertHistory(History history) {
		jdbcTemplate.update("insert into history(pid,type,title,authorId,version,priority,source,rational,createdtime,updateUserId,updatedtime,status," +
								"description,cost,effort,risk,updatedtimes,category,artifactid) " +
							"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
							new Object[]{
								history.getPid(),
								history.getType(),
								history.getTitle(),
								history.getAuthorId(),
								history.getVersion(),
								history.getPriority(),
								history.getSource(),
								history.getRational(),
								history.getCreatedtime(),
								history.getUpdateUserId(),
								history.getUpdatedtime(),
								history.getStatus(),
								history.getDescription(),
								history.getCost(),
								history.getEffort(),
								history.getRisk(),
								history.getUpdatedtimes(),
								history.getCategory(),
								history.getArtifactid()
							},new int[] {
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.TIMESTAMP,
								java.sql.Types.INTEGER,
								java.sql.Types.TIMESTAMP,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER,
								java.sql.Types.VARCHAR,
								java.sql.Types.INTEGER
							});
	}

	
}
